package it.patterns.structural.composite;

import java.util.ArrayList;

public class Component extends Composite {
	ArrayList<Composite> children = new ArrayList<Composite>();

	public Component(String name) {
		super(name);
	}

	@Override
	public String operation() {
		return "the component " + name;
	}

	@Override
	public void add(Composite composite) throws Exception {
		children.add(composite);
	}

	@Override
	public void remove(Composite composite) throws Exception {
		children.remove(composite);
	}

	@Override
	public void getChild() throws Exception {
		for (Composite c : children) {
			System.out.println(name + " contains " + c.operation());
			if (c instanceof Component) 
				c.getChild();
			
		}
	}
}
